using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;

namespace TestPermission.Module
{
    public partial class ActionAccessPermissionController : ViewController
    {
        public ActionAccessPermissionController()
        {
            InitializeComponent();
            RegisterActions(components);
            TargetViewType = ViewType.DetailView;
            TargetObjectType = typeof(ActionAccessPermission);
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            View.Model.GetNode<IModelViewItems>("Items")
                .GetNode<IModelPropertyEditor>("ActionId")
                .PredefinedValues = GetPredefinedValues();
        }
        private string GetPredefinedValues()
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in base.Application.Model.ActionDesign.Actions)
            {
                sb.Append(item.Id).Append(";");
            }
            return sb.ToString().TrimEnd(';');
        }
    }
}
